using System;
using System.Collections.Generic;

using IBatisNet.Common;
using IBatisNet.DataMapper;

using log4net;

using GymManager.Exception;
using GymManager.Persistence.VO;

namespace GymManager.Persistence.DAO
{
    /// <summary>
    /// Class responsible by getting information from database about stock item purchasing
    /// </summary>
    public class StockItemPurchaseDAO
    {
        // logger instance
        private ILog _logManager = LogManager.GetLogger(typeof(StockItemPurchaseDAO));

        /// <summary>
        /// Method responsible by adding a new stock item purchasing register to database
        /// </summary>
        /// <param name="StockItemPurchase">stock item purchasing information to be saved</param>
        /// <see cref="GymManager.Exception.PersistenceException"/>
        public void create(StockItemPurchase stockItemPurchaseVO)
        {
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("Begin Method");
            }

            try
            {
                ISqlMapper ibatisMapper = DAOManager.getInstance();
                ibatisMapper.Insert("StockItemPurchase.insert", stockItemPurchaseVO);
            }
            catch (System.Exception ex)
            {
                _logManager.Error("Error while saving stock item purchasing information", ex);
                throw new PersistenceException("Error while saving stock item purchasing information", ex);
            }

            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("End Method");
            }
        }
     }
}
